package br.com.unieuro.servlet;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.unieuro.dominio.Config;
import br.com.unieuro.facade.ManterConfigFacade;

public class FrontControllerConfig extends HttpServlet {
	public void doPost(HttpServletRequest req, HttpServletResponse resp)throws IOException, ServletException {

		String pagina = req.getParameter("pagina");
		if ((pagina != null) && (pagina.equals("configurar"))) {
			
			ManterConfigFacade facade = new ManterConfigFacade();		
			
				Config conf = new Config();
				conf.seteHoriz(Integer.valueOf(req.getParameter("eixoHorizontal")));
				conf.seteVert(Integer.valueOf(req.getParameter("eixoVertical")));
				conf.setTolerancia(Integer.valueOf(req.getParameter("tolerancia")));
				conf.setEstabilizador(Integer.valueOf(req.getParameter("estabilizador")));
				conf.setTempoCompara(Integer.valueOf(req.getParameter("tempoCompara")));
				conf.setEndImgBase(req.getParameter("endImgBase"));
				conf.setEndImgAtual(req.getParameter("endImgAtual"));
				conf.setEndImgFinal(req.getParameter("endImgFinal"));
				facade.updateConfig(conf);
				
				ArrayList<Config> lista = facade.pesquisarConfiguracoes();
				req.getSession().setAttribute("listaConf", lista);
				resp.sendRedirect("jsp/configuracoes.jsp");
			}
		
		if ((pagina != null) && (pagina.equals("listConf"))) {
			ManterConfigFacade facade = new ManterConfigFacade();
			ArrayList<Config> lista = facade.pesquisarConfiguracoes();
			req.getSession().setAttribute("listaConf", lista);

			resp.sendRedirect("jsp/Configuracoes.jsp");
		}
	}
}
